<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('信披报告') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('申请标题')" prop="actTitle">
        <el-input v-model="queryParams.actTitle" :placeholder="$t('申请标题')" size="small" @keyup.enter.native="queryHandle" />
      </el-form-item>
      <el-form-item :label="$t('披露对象')" prop="disclosureObject">
        <el-select v-model="queryParams.disclosureObject" :placeholder="$t('披露对象')" clearable>
          <el-option
            v-for="dict in disclosureObjectOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('披露类型')" prop="disclosureType">
        <el-select v-model="queryParams.disclosureType" :placeholder="$t('披露类型')" clearable>
          <el-option
            v-for="dict in disclosureTypeOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('报告期-年')" prop="reportPeriodYear">
        <DatePicker
          v-model="queryParams.reportPeriodYear"
          type="year"
          value-format="yyyy"
          format="yyyy"
          :placeholder="$t('报告期-年')"
        />
      </el-form-item>
      <el-form-item :label="$t('报告期-季')" prop="reportPeriodSeason">
        <el-select v-model="queryParams.reportPeriodSeason" :placeholder="$t('报告期-季')" clearable>
          <el-option
            v-for="dict in reportPeriodSeasonOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['fund:disclosure:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t("新增") }}</el-button>
      </el-col>
      <!--<el-col :span="1.5">
        <el-button
          v-hasPermi="['fund:disclosure:export']"
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportHandle"
        >{{ $t("导出") }}</el-button>
      </el-col>-->
    </el-row>

    <el-table v-loading="loading" :data="fundDisclosureList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请标题')" align="center" prop="actTitle" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span class="link-type" @click="updateHandle(scope.row)">{{ scope.row.actTitle }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('披露对象')" align="center" prop="disclosureObject" :formatter="disclosureObjectFormat" show-overflow-tooltip width="150" />
      <el-table-column :label="$t('披露类型')" align="center" prop="disclosureType" :formatter="disclosureTypeFormat" show-overflow-tooltip width="110" />
      <el-table-column :label="$t('报告期-年')" align="center" prop="reportPeriodYear" show-overflow-tooltip width="110" />
      <el-table-column :label="$t('报告期-季')" align="center" prop="reportPeriodSeason" :formatter="reportPeriodSeasonFormat" show-overflow-tooltip width="110" />
      <el-table-column :label="$t('报告类型')" align="center" prop="reportType" :formatter="reportTypeFormat" show-overflow-tooltip width="110" />
      <el-table-column :label="$t('审批状态')" align="center" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" fixed="right" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <!-- 启动流程，终止流程，修改，删除 四个按钮 -->
          <ListBtn :bus-data="scope.row" has-permi="fund:disclosure" />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改信息披露对话框 -->
    <el-dialog :title="title" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <fundDisclosureForm ref="fundDisclosureForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listFundDisclosure, delFundDisclosure } from '@/api/fund/disclosure/fundDisclosure'
import fundDisclosureForm from './fundDisclosureForm.vue'
import ProcessStatus from '@/components/Act/ProcessStatus/index'
import { downLoadExcel } from '@/utils/excelDownload'
export default {
    components: {
        fundDisclosureForm,
        ProcessStatus
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 信息披露表格数据
          fundDisclosureList: [],
          // 弹出层标题
          title: '',
          // 是否显示弹出层
          formOpen: false,
        // 披露对象字典
        disclosureObjectOptions: [],
        // 披露类型字典
        disclosureTypeOptions: [],
        // 报告期-季字典
        reportPeriodSeasonOptions: [],
        reportTypeOptions: [], // 报告类型字典
          // 查询参数
          queryParams: {
              disclosureObject: undefined,
              disclosureType: undefined,
              reportPeriodYear: undefined,
              reportPeriodSeason: undefined,
              fundId: this.$route.query.id,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
      this.getList()
      this.getDicts('fund_disclosure_object').then(response => {
          this.disclosureObjectOptions = response.data
      })
      this.getDicts('fund_disclosure_type').then(response => {
          this.disclosureTypeOptions = response.data
      })
      this.getDicts('fund_disclosure_quarter').then(response => {
          this.reportPeriodSeasonOptions = response.data
      })
      this.getDicts('fund_report_type').then(response => {
        this.reportTypeOptions = response.data
      })
  },
  methods: {
    /** 查询信息披露列表 */
    getList() {
        this.loading = true
        listFundDisclosure(this.queryParams).then(response => {
            this.fundDisclosureList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    // 披露对象字典翻译
    disclosureObjectFormat(row) {
      return this.selectDictLabel(this.disclosureObjectOptions, row.disclosureObject)
    },
    // 披露类型字典翻译
    disclosureTypeFormat(row) {
      return this.selectDictLabel(this.disclosureTypeOptions, row.disclosureType)
    },
    // 报告期-季字典翻译
    reportPeriodSeasonFormat(row) {
      return this.selectDictLabel(this.reportPeriodSeasonOptions, row.reportPeriodSeason)
    },
    // 报告类型-季字典翻译
    reportTypeFormat(row) {
      return this.selectDictLabel(this.reportTypeOptions, row.reportType)
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            disclosureObject: undefined,
            disclosureType: undefined,
            reportPeriodYear: undefined,
            reportPeriodSeason: undefined,
            remark: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined,
            actId: undefined,
            actStatus: undefined,
            fundId: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.title = this.$t('添加信披报告')
        this.$nextTick(() => {
            this.$refs.fundDisclosureForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.title = this.$t('修改信披报告')
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.fundDisclosureForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delFundDisclosure(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        downLoadExcel('/disclosure/fundDisclosure/export', this.queryParams)
    }
  }
}
</script>
